package com.gupaoedu.vip.netty.io.bio.tomcat.http;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @program:gupaoedu-vip-netty-io
 * @description:封装OutputStream
 * @author:Gongchao
 * @date:2020-04-26
 **/
public class GPResponse {

    private OutputStream outputStream;

    public GPResponse(OutputStream outputStream) {
        this.outputStream = outputStream;
    }
    
    /* *
     * @description:输出满足http协议的数据
     * @author:Gongchao
     * @date:2020-四月-26
     * @param:[s] 
     * @return:void
     */
    public void write(String s) throws IOException {
        //使用http协议，输出也要满足http协议
        //给出状态码 200
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("HTTP/1.1 200 OK\n")
                .append("Content-Type:text/html;\n")
                .append("\r\n").append(s);
        outputStream.write(stringBuilder.toString().getBytes());
    }

}
